// Domien Nowicki
#include "QtPusherSprite.h"
#include <QPainter>
#include "QtSequentialAnimationEffect.h"
#include "QtTranslateToEffect.h"

QtPusherSprite::QtPusherSprite(QtSprite *parent): QtPixmapSprite(parent), duration(500)
{
	SetDepth(1);
	SetResource("foreground", "pusher");
}

QtPusherSprite::~QtPusherSprite()
{
}


void QtPusherSprite::SetDirection(const Direction& direction)
{
	switch(direction.Type())
	{
		case Direction::NORTH:
			SetAngle(0);
		break;

		case Direction::SOUTH:
			SetAngle(180);
		break;
	
		case Direction::WEST:
			SetAngle(270);
		break;
	
		case Direction::EAST:
			SetAngle(90);
		break;
	}
}

void QtPusherSprite::SetCellSize(unsigned int width, unsigned int height)
{
	SetCenterPoint(QPointF(width/2, height/2));

	pushPoint = QPointF(width/2, height/3);
}

void QtPusherSprite::Push()
{
	QtTranslateToEffect effect;

	effect.SetDuration(duration/2);
	effect.SetTarget(this);
	effect.SetEndPosition(pushPoint);

	AddEffect(&effect);

	effect.SetDuration(duration);
	effect.SetTarget(this);
	effect.SetEndPosition(CenterPoint());

	AddEffect(&effect);
	Start();
}







